package com.qq.BFMRSE.util;

import java.io.File;
import java.io.IOException;

import com.qq.BFMRSE.entity.wordCountInfo;
import com.qq.BFMRSE.extractWord.wordTFAndIDFInfo;
import com.qq.BFMRSE.serialize.objectSerializeUtil;

public class UserParamManager {
	private  static wordCountInfo wcInfo;
	public static String wcInfoPath=BFConstants.WORDINFOFILE+File.separator+BFConstants.WORDCOUNTINFO;
	static{
		File file=new File(wcInfoPath);
		if(file.exists()&&!file.isDirectory()){
			try {
				wcInfo=(wordCountInfo) objectSerializeUtil.deserialize(wcInfoPath);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else {
			wcInfo=new wordCountInfo();
		}
	}
	public static int getVectorLength(){
		return wcInfo.getN();
	}
	public static int getDistintWordCount(){
		return wcInfo.getDistinctN();
	}
	/**
	 * 是否进行秘钥扩展
	 * @return
	 */
	public static boolean canExtentSecretLength(){
		return wcInfo.isExtendFlag();
	}
	public static void update(){
		int distinctN=wordTFAndIDFInfo.idfMap.keySet().size();
		int dummuyN=wcInfo.getN()-distinctN;
		wcInfo.setDistinctN(distinctN);
		wcInfo.setDummuyN(dummuyN);
		if(dummuyN>=0){
			wcInfo.setExtendFlag(false);
		}else {
			wcInfo.setExtendFlag(true);
		}
		try {
			objectSerializeUtil.serialize(wcInfo, wcInfoPath);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void setWcInfo(wordCountInfo wcIn){
		wcInfo=wcIn;
		try {
			objectSerializeUtil.serialize(wcInfo, wcInfoPath);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	

}
